package cn.shujuhai.cms.controller.struct;

import cn.shujuhai.cms.domain.Recipient;
import cn.shujuhai.cms.domain.Struct;
import cn.shujuhai.cms.domain.StructParam;
import cn.shujuhai.cms.service.StructService;
import cn.shujuhai.common.aop.SysLog;
import cn.shujuhai.common.domain.PageRequest;
import cn.shujuhai.common.pluging.data.ResultVo;
import com.github.pagehelper.PageInfo;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: NiuYaHu
 * @Date: 2025/8/5 15:12
 * @Description:
 **/
@RestController
@RequestMapping("/cms/struct")
@RequiredArgsConstructor
public class StructController {
    private final StructService structService;

    /**
     * 查询结构列表
     *
     * @param name        中文名称
     * @param pageRequest
     * @return 查询的结构列表
     */
    @SysLog(value = "结构列表查询", operationType = "查询", module = "结构模块")
    @GetMapping("/list")
    public ResultVo<PageInfo<Struct>> getStructList
    (@Validated String name, @Valid PageRequest pageRequest) {
        return this.structService.getStructPageInfo(name, pageRequest.getPageNum(), pageRequest.getPageSize());
    }

    /**
     * 结构新增
     *
     * @param struct 结构
     * @return 结构新增
     */
    @SysLog(value = "结构新增", operationType = "新增", module = "结构模块")
    @PostMapping("/add")
    public ResultVo<?> save(@RequestBody Struct struct) {
        return this.structService.add(struct);
    }

    /**
     * 结构编辑
     *
     * @param struct 结构
     * @return 结构新增
     */
    @SysLog(value = "结构编辑", operationType = "编辑", module = "结构模块")
    @PostMapping("/update")
    public ResultVo<?> edit(@RequestBody Struct struct) {
        return this.structService.edit(struct);
    }

    /**
     * 结构删除
     *
     * @param structId 结构Id
     * @return 结构新增
     */
    @SysLog(value = "结构删除", operationType = "删除", module = "结构模块")
    @PostMapping("/delete/{structId}")
    public ResultVo<?> delete(@PathVariable Long structId) {
        return this.structService.removeId(structId);
    }

    /**
     * 根据结构Id获取结构项
     *
     * @param structId 结构Id
     * @return 获取的结构项集合
     */
    @GetMapping("/getStructParamByStructId")
    public ResultVo<?> getStructParamByStructId(@RequestParam Long structId) {
        return this.structService.getStructParamByStructId(structId);
    }

    /**
     * 根据结构列表
     *
     * @return 获取的结构集合
     */
    @GetMapping("/getStructList")
    public ResultVo<?> getStructList() {
        return this.structService.getStructList();
    }
}
